package com.oop12.exception;

public class Teacher {
	int age;
	String schoolName;
	String teachName;

	public void setSchoolName(String schoolName) {
		this.schoolName = schoolName;
	}

	public void setTeachName(String teachName) {
		this.teachName = teachName;
	}

	public void setAge(int age) throws Exception {
		if (age < 22) {
			throw new Exception("老师年龄必须大于22岁！");
		}
		this.age = age;
	}

	public void classes() {
		System.out.println("我是" + teachName + "，现在开始上课！");
	}

	public void show() {
		System.out.println("我是" + teachName + "，今年" + age + "岁，在" + teachName + "当老师。");
	}

	public static void main(String[] args) {
		// TODO Auto-generated method stub

		try {
			Teacher liu = new Teacher();
			liu.setAge(23);
			liu.setSchoolName("新东方");
			liu.setTeachName("刘老师");
			liu.classes();
			liu.show();
			liu.setAge(20);
		} catch (Exception e) {
			System.out.println("捕捉到异常！");
			e.printStackTrace();
		}

	}

}
